package com.hzhc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzhc.entity.ChargeItem;
import com.hzhc.mapper.ChargeItemMapper;
import com.hzhc.service.ChargeItemService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.vo.ChargeItemVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 计费项目 服务实现类
 * </p>
 *
 * @author 1
 * @since 2024-05-28
 */
@Service
@RequiredArgsConstructor
public class ChargeItemServiceImpl extends ServiceImpl<ChargeItemMapper, ChargeItem> implements ChargeItemService {

    @Override
    public List<ChargeItemVo> getAllList(Page<ChargeItemVo> page, ChargeItemVo vo) {

        IPage<ChargeItemVo> iPage = baseMapper.getAllList(page,vo);
        return iPage.getRecords();
    }

    @Override
    public ResultUtil<T> addChargeItem(ChargeItem item) {
        if (save(item)){
            return ResultUtil.ok();
        }
        return ResultUtil.fail();
    }

    @Override
    public ResultUtil<T> updateChargeItem(ChargeItem item) {
        if (updateById(item)){
            return ResultUtil.ok();
        }
        return ResultUtil.fail();
    }

    @Override
    public ResultUtil<T> delChargeItem(Long id) {
        ChargeItem item = getById(id);
        item.setDisable(true);//1
        if (updateById(item)){
            return ResultUtil.ok();
        }
        return ResultUtil.fail();
    }

    @Override
    public List<ChargeItemVo> selectChargeItemList(ChargeItemVo vo) {
        return baseMapper.getAllList(vo);
    }

    @Override
    public List<ChargeItemVo> getChargeItemVoList(String chargeItemIds) {
        List<ChargeItemVo> chargeItemVos= baseMapper.getChargeItemVoList(chargeItemIds);
        return chargeItemVos;
    }

}
